#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include<pthread.h>
#include<sys/types.h>
#include<unistd.h>

//循环创建子进程，并输出为第几个

//线程执行函数
void *mythread(void *arg)
{	
	int i = *(int *)arg;
	printf("this is [%d] thread,pid==[%d],id==[%ld]\n",i,getpid(),pthread_self());
}


//创建子线程
int main()
{
	int ret;
	int i = 0;
	pthread_t thread[5];
	int j[5] = {0, 1,2,3,4};
	for(i;i<5;i++)
	{
		ret = pthread_create(&thread[i],NULL,mythread,&j[i]);
		if(ret !=0)
		{
			printf("pthread_creat error,[%s]\n",strerror(ret));
			return -1;
		}
	//	sleep(1);
	}
	printf("main thread,pid==[%d],id==[%ld]\n",getpid(),pthread_self());
	//为了让子线程能够执行起来
	sleep(1);
	return 0;
}
